﻿using System;
using System.Text;

namespace dotHTML.HTML {
    /// <summary>
    /// Represents a command which the user can invoke.
    /// </summary>
    [Standalone]
    [Serializable]
    public class Command : Element {
        /// <summary>
        /// Defines the possible types of command.
        /// </summary>
        public enum TypeChoices {
            /// <summary>
            /// Indicates that this is a normal command.
            /// </summary>
            Command,
            /// <summary>
            /// Indicates that the command can be toggled using a checkbox.
            /// </summary>
            Checkbox,
            /// <summary>
            /// Indicates that the command can be toggled using a radio button.
            /// </summary>
            Radio
        }

        private bool _checked;
        private bool _disabled;
        private string _icon;
        private string _label;
        private string _radiogroup;
        private TypeChoices? _type;

        /// <summary>
        /// Determines whether or not this command is checked.
        /// </summary>
        public bool Checked {
            get { return _checked; }
            set { _checked = value; }
        }

        /// <summary>
        /// Determines whether or not this command is disabled.
        /// </summary>
        public bool Disabled {
            get { return _disabled; }
            set { _disabled = value; }
        }

        /// <summary>
        /// Gets or sets the URL of an icon that represents this command.
        /// </summary>
        public string Icon {
            get { return _icon; }
            set { _icon = value; }
        }

        /// <summary>
        /// Gets or sets the label of this command.
        /// </summary>
        public string Label {
            get { return _label; }
            set { _label = value; }
        }

        /// <summary>
        /// Gets or sets the group of radio buttons corresponding to this
        /// command's radio button.
        /// </summary>
        public string RadioGroup {
            get { return _radiogroup; }
            set { _radiogroup = value; }
        }

        /// <summary>
        /// Determines the type of command this is.
        /// </summary>
        public TypeChoices? Type {
            get { return _type; }
            set { _type = value; }
        }

        /// <summary>
        /// Gets a formatted string of all local attributes of this element
        /// (not including the base attributes).
        /// </summary>
        /// <param name="sb">The StringBuilder to write this element's
        /// attribute data to.</param>
        protected override void WriteLocalAttributes(StringBuilder sb) {
            AttributeWriter.Write(sb, _checked, "checked");
            AttributeWriter.Write(sb, _disabled, "disabled");
            AttributeWriter.Write(sb, _icon, "icon");
            AttributeWriter.Write(sb, _label, "label");
            AttributeWriter.Write(sb, _radiogroup, "radiogroup");
            AttributeWriter.Write(sb, _type, "type", true);
        }
    }
}
